home *** CD-ROM | disk | FTP | other *** search
/ Die Ultimative Software-P…i Collection 1996 & 1997 / Die Ultimative Software-Pakete CD-ROM fur Atari Collection 1996 & 1997.iso / g / gnu_c / pmllib21.zoo / ccos.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-12  |  4.3 KB  |  203 lines

  1. /************************************************************************
  2.  *                                    *
  3.  *                N O T I C E                *
  4.  *                                    *
  5.  *            Copyright Abandoned, 1987, Fred Fish        *
  6.  *                                    *
  7.  *    This previously copyrighted work has been placed into the    *
  8.  *    public domain by the author (Fred Fish) and may be freely used    *
  9.  *    for any purpose, private or commercial.  I would appreciate    *
  10.  *    it, as a courtesy, if this notice is left in all copies and    *
  11.  *    derivative works.  Thank you, and enjoy...            *
  12.  *                                    *
  13.  *    The author makes no warranty of any kind with respect to this    *
  14.  *    product and explicitly disclaims any implied warranties of    *
  15.  *    merchantability or fitness for any particular purpose.        *
  16.  *                                    *
  17.  ************************************************************************
  18.  */
  19.  
  20. /*
  21.  *  FUNCTION
  22.  *
  23.  *    ccos   complex double precision cosine
  24.  *
  25.  *  KEY WORDS
  26.  *
  27.  *    ccos
  28.  *    complex functions
  29.  *    machine independent routines
  30.  *    math libraries
  31.  *
  32.  *  DESCRIPTION
  33.  *
  34.  *    Computes double precision complex cosine of a double
  35.  *    precision complex argument.
  36.  *
  37.  *  USAGE
  38.  *
  39.  *    COMPLEX ccos (z)
  40.  *    COMPLEX z;
  41.  *
  42.  *  REFERENCES
  43.  *
  44.  *    Fortran 77 user's guide, Digital Equipment Corp. pp B-12
  45.  *
  46.  *  PROGRAMMER
  47.  *    
  48.  *    Fred Fish
  49.  *    Tempe, Az 85281
  50.  *    (602) 966-8871
  51.  *
  52.  *  INTERNALS
  53.  *
  54.  *    Computes complex cosine of z = x + j y from:
  55.  *
  56.  *        1.    r_ccos = cos(x) * cosh(y)
  57.  *
  58.  *        2.    i_ccos = -sin(x) * sinh(y)
  59.  *
  60.  *        3.    ccos(z) = r_ccos + j i_ccos
  61.  *
  62.  */
  63.  
  64. #if !defined (__M68881__) && !defined (sfp004)
  65.  
  66. #include <stdio.h>
  67. #include <math.h>
  68. #include "pml.h"
  69.  
  70.  
  71. COMPLEX ccos (z)
  72. COMPLEX z;
  73. {
  74.     COMPLEX result;
  75.  
  76.     result.real = cos(z.real) * cosh(z.imag);
  77.     result.imag = -sin(z.real) * sinh(z.imag);
  78.     return (result);
  79. }
  80. #endif !defined (__M68881__) && !defined (sfp004)
  81.  
  82. #if defined (__M68881__) || defined (sfp004)
  83. # ifdef ERROR_CHECK    /* no error checking for now    */
  84. __asm("
  85. .text
  86. _funcname:
  87.     .ascii    \"ccos\\0\"
  88.     .even");
  89. # endif ERROR_CHECK
  90. #endif defined (__M68881__) || defined (sfp004)
  91.  
  92. #ifdef    __M68881__
  93. __asm("
  94. .text
  95.     .globl _ccos
  96. _ccos:
  97.     movel    a1,d0        | save a1 as return value
  98.     fmoved    sp@(4),fp0    | z.real
  99.     fsinx    fp0,fp1        | cos(z.real)
  100.     fcosx    fp0,fp0        | sin(z.real)
  101.     fnegx    fp1,fp1        |-sin(z.real)
  102.  
  103.     fmoved    sp@(12),fp3    | z.imag
  104.     fcoshx    fp3,fp2        | cosh(z.imag)
  105.     fsinhx    fp3,fp3        | sinh(z.imag)
  106.     
  107.     fmulx    fp2,fp0        | result.real
  108.     fmoved    fp0,a1@        |
  109.     fmulx    fp3,fp1        | result.imag
  110.     fmoved    fp1,a1@(8)    |
  111. ");    /* end asm    */
  112. #endif    __M68881__
  113.  
  114. #ifdef    sfp004
  115. __asm("
  116. | double precision floating point stuff for Atari-gcc using the SFP004
  117. | developed with gas
  118. |
  119. | double precision complex sin
  120. |
  121. | M. Ritzert (mjr at dmzrzu71)
  122. |
  123. | 12.10.1990
  124. |
  125. | addresses of the 68881 data port. This choice is fastest when much data is
  126. | transferred between the two processors.
  127.  
  128. comm =     -6
  129. resp =    -16
  130. zahl =      0
  131.  
  132. | waiting loop ...
  133. |
  134. | wait:
  135. | ww:    cmpiw    #0x8900,a1@(resp)
  136. |     beq    ww
  137. | is coded directly by
  138. |    .long    0x0c688900, 0xfff067f8
  139. | and
  140. | www:    tst.b    a1@(resp)
  141. |    bmi.b    www
  142. | is coded by
  143. |    .word    0x4a68,0xfff0,0x6bfa        | test
  144.  
  145.     .text; .even
  146.     .globl _ccos
  147. _ccos:
  148.     movel    a1,d0                | save a1 as return value
  149.     lea    0xfffa50,a0            | fpu address
  150.  
  151.     movew    #0x54b0,a0@(comm)        | sincos: sin -> fp1
  152.     .long    0x0c688900, 0xfff067f8        |      cos -> fp0
  153.     movel    sp@(4), a0@            | load z.real
  154.     movel    sp@(8), a0@            | load z.real
  155.  
  156. |    fmoved    sp@(12),fp3            | z.imag to fp3
  157.     movew    #0x5580,a0@(comm)
  158.     .long    0x0c688900, 0xfff067f8
  159.     movel    sp@(12),a0@
  160.     movel    sp@(16),a0@
  161.  
  162. |    fcoshx    fp3,fp2                | cosh(z.imag)
  163.     movew    #0x0d19,a0@(comm)
  164.     .word    0x4a68,0xfff0,0x6bfa        | test
  165. |    fsinhx    fp3,fp3                | sinh(z.imag)
  166.     movew    #0x0d82,a0@(comm)
  167.     .word    0x4a68,0xfff0,0x6bfa        | test
  168. |    fmulx    fp2,fp0                | result.real
  169.     movew    #0x0823,a0@(comm)
  170.     .word    0x4a68,0xfff0,0x6bfa        | test
  171. |    fmoved    fp0,a1@                |
  172.     movew    #0x7400,a0@(comm)        | 
  173.     .long    0x0c688900, 0xfff067f8
  174.     movel    a0@,a1@
  175.     movel    a0@,a1@(4)
  176. |    fmulx    fp3,fp1                | result.imag
  177.     movew    #0x0ca3,a0@(comm)
  178.     .word    0x4a68,0xfff0,0x6bfa        | test
  179. |    fnegx    fp1,fp1
  180.     movew    #0x049a,a0@(comm)
  181.     .word    0x4a68,0xfff0,0x6bfa        | test
  182. |    fmoves    fp1,d1                |
  183.     movew    #0x7480,a0@(comm)        |
  184.     .long    0x0c688900, 0xfff067f8
  185.     movel    a0@,a1@(8)
  186.     movel    a0@,a1@(12)
  187. ");    /* end asm    */
  188. #endif    sfp004
  189.  
  190.  
  191. #if defined (__M68881__) || defined (sfp004)
  192. # ifdef ERROR_CHECK    /* no error checking for now    */
  193. __asm("
  194.     pea    _funcname
  195.     jmp    c_err_check
  196. ");    /* end asm    */
  197. # else  ERROR_CHECK
  198.  
  199. __asm("rts");
  200.  
  201. # endif ERROR_CHECK
  202. #endif defined (__M68881__) || defined (sfp004)
  203.